AddCSLuaFile("wirecheck.lua")
require("datastream") -- Required to send stuff from client to server


if CLIENT then
-------------------------
-- CLIENT PART         --
-------------------------

CreateClientConVar("wiremod_check_success",0,false,true)
usermessage.Hook("wiremod_check_init",function(um)
	for _,path in ipairs(file.FindDir("../addons/*")) do
		if path:lower() == "wire" then
			RunConsoleCommand("wiremod_check_success","1")
			break
		end
	end
end)

else
-------------------------
-- SERVER PART         --
-------------------------

local clients_pending = {}

-- Timeout check
local function timeout(pl)
	clients_pending[pl] = nil
	if pl:GetInfoNum("wiremod_check_success") then
		Msg("Wiremod check for "..pl:GetName().." succeded.\n")
	else
		Msg("Wiremod check for "..pl:GetName().." failed or timed out.\n")
		pl:Kick("This server requires Wiremod. Download it from http://www.wiremod.com")
	end
end

-- Ask client to check if they have wiremod
hook.Add("PlayerInitialSpawn","wiremod_check_addtoqueue",function(pl)
	Msg(pl:GetName().." spawned, sending wiremod check...\n")
	clients_pending[pl] = true
	timer.Create("wiremod_check_timeout_"..pl:GetName(), 10, 1, timeout, pl)
	
	umsg.Start("wiremod_check_init",pl)
	umsg.End()
end)

-- End Server
end